//查询用户信息
function searchUserInfo() {
    return new Promise((resolve, reject) => {
        axios({
            method: 'get',
            url: '/amc/sys/base/user/search',
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token}
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function searchUsersOfAgency(agencyCode) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'get',
            url: '/amc/sys/base/user/search/agency/'+agencyCode,
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token}
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function saveUser(userInfos) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'post',
            url: '/amc/sys/base/user/save',
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token},
            data: userInfos
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function cancelUser(userId, status) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'put',
            url: '/amc/sys/base/user/cancel/'+userId+"/"+status,
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token}
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function deleteUsers(userIds) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'delete',
            url: '/amc/sys/base/user/deletes',
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token},
            data: userIds
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function updateUser(userinfos) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'put',
            url: '/amc/sys/base/user/update',
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token},
            data: userinfos
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function assignedGroup(userId, groups) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'put',
            url: '/amc/sys/base/user/assign/group/'+userId,
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token},
            data: groups
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function assignedRole(userId, groupId, roles) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'put',
            url: '/amc/sys/base/user/assign/role/'+groupId+'/'+userId,
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token},
            data: roles
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}